import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    tokenOverTime:"",
    userId:"",
    isAdmin:false,
    routerList:[]
  },
  getters: {
  },
  mutations: {
    setTokenOverTime(state,overTime){
      state.overTime = overTime;
    },
    setUserId(state,id){
      state.userId = id;
    },
    setIsAdmin(state,flag){
      state.isAdmin = flag;
    },
    setRouterList(state,config){
      state.routerList = config;
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [    
    // 把vuex的数据存储到sessionStorage    
    createPersistedState({      
        storage: window.localStorage,      
        reducer(val) {        
            return {          
                // 只存储state中的userData          
                isAdmin: val.isAdmin        
            }      
        }    
    }),  
],
})
